package com.zw.commons.security.custom;/*
 *@program:java-cloud-prevalence
 *@author:zw
 *@Time: 2022/12/10
 *@description: 自定义密码加密
 */

import com.zw.commons.constants.UserConstants;
import com.zw.commons.utlis.MD5;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

@Component
public class CustomMd5Password implements PasswordEncoder {

    @Override
    public String encode(CharSequence rawPassword) {
        return MD5.encrypt(rawPassword.toString()+ UserConstants.USER_SLAT);
    }
    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        String password = MD5.encrypt(rawPassword.toString() + UserConstants.USER_SLAT);
        return encodedPassword.equals(password);
    }
}
